import { ml_hideLoading, ml_showLoading, ml_showToast, ml_Toast } from '../../../utils/asyncWX'
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mail_money: '',
    mail_weight: '',
    mail_inf: '',
    mail_list: null,   //快件基本信息
  },
  //获取输入框内容
  mail_money(e) { this.setData({ mail_money: e.detail.value }) },
  mail_weight(e) { this.setData({ mail_weight: e.detail.value }) },
  mail_inf(e) { this.setData({ mail_inf: e.detail.value }) },

  ifnone() {
    if (this.data.mail_money == '') { return '请填写快件价格！' }
    if (this.data.mail_weight == '') { return '请填写快件重量！' }
    if (this.data.mail_inf == '') { return '请填写快件信息！' }
    return 200;
  },

  sead_money() {
    let isnone = this.ifnone();
    if (isnone == 200) {
      ml_showLoading();
      wx.cloud.callFunction({
        name: 'getorder_list', data: {
          type: 'mail_money',
          id: this.data.mail_list._id,
          mail_money: this.data.mail_money,
          mail_weight: this.data.mail_weight,
          mail_inf: this.data.mail_inf
        }
      }).then(res => {
        ml_hideLoading();
        console.log(res)
        if (res.result.stats.updated == 1) {
          ml_showToast('发送成功');
          wx.navigateBack({delta: 1})
        } else {
          ml_Toast('发送失败，请重新尝试！')
        }
      })
    } else {
      ml_Toast(isnone);
    }

  },

  // 获取时间
  gettime() {
    //获取时间
    let myDate = new Date();
    let Dates = ((myDate.getMonth() + 1) < 10 ? ('0' + (myDate.getMonth() + 1)) : (myDate.getMonth() + 1)) + "-" + (myDate.getDate() < 10 ? ('0' + myDate.getDate()) : myDate.getDate());
    let times = (myDate.getHours() < 10 ? ('0' + myDate.getHours()) : myDate.getHours()) + ':' + (myDate.getMinutes() < 10 ? ('0' + myDate.getMinutes()) : myDate.getMinutes()) + ':' + (myDate.getSeconds() < 10 ? ('0' + myDate.getSeconds()) : myDate.getSeconds());
    let apm = myDate.getHours() <= 12 ? '上午' : '下午';
    return { 'Dates': Dates, 'times': times, 'apm': apm };
  },
  // 取消订单
  close_order() {
    let _id = this.data.mail_list._id;
    let rider_inf = app.globalData.rider_inf
    wx.cloud.callFunction({
      name: 'getorder_list', data: {
        type: 'back_rider',
        id: _id,
        rider_inf: rider_inf
      }
    }).then(res => {
      console.log(res);
      if (res.result.rider_inf.stats.updated == 1) {
        wx.navigateBack({
          delta: 2,
        })
      } else {
        ml_Toast('取消失败！');
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let items = JSON.parse(options.obj);
    this.setData({ mail_list: items })
    console.log(items);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})